package com.gouaixin.bee.beeframework2.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.util.AbToastUtil;
import com.gouaixin.bee.beeframework2.MyAPI;
import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.model.EncodeIdModel;
import com.gouaixin.bee.beeframework2.tool.PreferencesUtils;
import com.gouaixin.bee.beeframework2.bean.BaseModel;
import com.lidroid.xutils.http.RequestParams;

/**
 * Created by Administrator on 2015/3/23.
 */
//非VIP用户的搜索界面
public class B21_SearchNoActivity extends Activity {
    Context context = B21_SearchNoActivity.this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.b21_search_no);

        initHead();


    }

    private void initHead() {
        ImageView back;
        ImageView right;
        final TextView title;

        back = (ImageView) findViewById(R.id.back);
        right = (ImageView) findViewById(R.id.right);
        title = (TextView) findViewById(R.id.title);

        right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String id = title.getText().toString();

                String cid = PreferencesUtils.getString(context, "cid");
                if (id.equals(cid)) {
                    Intent intent5 = new Intent(context, B6_ziliaoActivity.class);
                    intent5.putExtra("isMe", true);
                    intent5.putExtra("HerId", "");
                    startActivity(intent5);
                    return;
                }


                if (id.length() == 8) {
                    String oldid = EncodeIdModel.decodeId(id);
                    searchWithId(oldid);
                } else {
                    AbToastUtil.showToast(context, "找不到你搜索的id");

                }


            }

        });

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


    }

    private void searchWithId(final String id) {


        String cid = PreferencesUtils.getString(context, "cid", "");

        BaseModel.setCallBackLister(new BaseModel.CallBackLister() {
            @Override
            public String onCallBack(String url, String data) {


                Intent it = new Intent().setClass(context, B6_ziliaoActivity.class);
                it.putExtra("HerId", id);
                startActivity(it);
                finish();
                return url;
            }
        });

        RequestParams params = new RequestParams();
        params.addBodyParameter("jid", id);
        params.addBodyParameter("cid", cid);
        BaseModel.post(MyAPI.detail, params);


    }
}
